package thu.infinity.commons;

import org.apache.thrift.TProcessor;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransport;

import thu.infinity.commons.AggregatorHandler;
import thu.infinity.thrift.Aggregator;

public class InfinityServer {
	public static void main(String[] args) {
		try {
			final AggregatorHandler handler = new AggregatorHandler();

			TProcessorFactory processorFactory = new TProcessorFactory(null) {
				@Override
				public TProcessor getProcessor(TTransport trans) {
					return new Aggregator.Processor(handler);
				}
			};

			TServerTransport serverTransport = new TServerSocket(9999);
			// Use this for a multithreaded server
			TServer server = new TThreadPoolServer(processorFactory,
					serverTransport);

			System.out.println("Starting the server...");
			server.serve();
	
		} catch (Exception x) {	
			x.printStackTrace();
		}
		System.out.println("Done.");
	}
}
